home *** CD-ROM | disk | FTP | other *** search
/ Aminet 51 / Aminet 51 (2002)(GTI - Schatztruhe)[!][Oct 2002].iso / Aminet / util / arc / xadmasterdev.lha / xad / Sources / clients / SOS.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-08-20  |  5.2 KB  |  183 lines

  1. /*
  2.  * Sanity Operating System (SOS) filesystem client for XAD.
  3.  * Copyright (C) 2000 Stuart Caie <kyzer@4u.net>
  4.  *
  5.  * Dirk Stoecker, author of the XAD library, is expressly permitted to
  6.  * include this software in his library without conditions or restrictions.
  7.  *
  8.  * For everyone else:
  9.  *
  10.  * This program is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published by
  12.  * the Free Software Foundation; either version 2 of the License, or
  13.  * (at your option) any later version.
  14.  * 
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  * 
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to the Free Software
  22.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  */
  24.  
  25. /* This XAD client reads 'Sanity Operating System' disks - trackdisk demos
  26.  * written by Sanity with a standard disk layout.
  27.  *
  28.  * The SOS disk structure is (C) 1992-1995 Dierk Ohlerich (Chaos/Sanity)
  29.  *
  30.  * $VER: SOS.c 1.2 (01.03.2000)
  31.  */
  32.  
  33. #include <libraries/xadmaster.h>
  34. #include <proto/xadmaster.h>
  35. #include <inline/xadmaster.h>
  36. #include <string.h>
  37.  
  38. #include "SDI_compiler.h"
  39. #include "ConvertE.c"
  40.  
  41.  
  42. #ifndef XADMASTERFILE
  43. #define SOS_Client        FirstClient
  44. #define NEXTCLIENT        0
  45. const UBYTE version[] = "$VER: SOS 1.2 (01.03.2000)";
  46. #endif
  47. #define SOS_VERSION        1
  48. #define SOS_REVISION        2
  49.  
  50.  
  51.  
  52. /* SOS disk structure:
  53.  * Block size = 512
  54.  *
  55.  * Block    0: bootblock - longword 'SOS1' at offset 16
  56.  * Blocks 1-n: SOS operating system code
  57.  * Block    n: first directory block. first file is always "loader"
  58.  *
  59.  * The array of SOSfile structures is terminated with an entry whose
  60.  * offset is 0 (and whose length is 0 and name is "")
  61.  */
  62.  
  63. struct SOSfile {
  64.   ULONG offset, size;
  65.   char name[24];
  66. };
  67.  
  68. /* SOS bootblock ids: dostype='DOS\0', id = 'SOS1' */
  69. struct SOSboot {
  70.   ULONG dostype, cksum, magic, branch, id;
  71. };
  72.  
  73.  
  74. #define FILESIZE (sizeof(struct SOSfile))
  75. #define BOOTSIZE (sizeof(struct SOSboot))
  76.  
  77. /* FILESEEK = 'having read a SOSfile, seek back onto a block boundary'
  78.  * BOOTSEEK = 'having read some bootblock data, seek enough such that a
  79.  *             subsequent FILESEEK will seek back onto a block boundary'
  80.  */
  81. #define FILESEEK (512 - FILESIZE)
  82. #define BOOTSEEK (512 - BOOTSIZE + FILESIZE)
  83.  
  84.  
  85. ASM(LONG) SOS_GetInfo(REG(a0, struct xadArchiveInfo *ai),
  86. REG(a6, struct xadMasterBase *xadMasterBase)) {
  87.  
  88.   struct TagItem tags[]  = {
  89.     { XAD_OBJNAMESIZE, 25 },
  90.     { TAG_DONE, 0 }
  91.   };
  92.  
  93.   struct TagItem datetags[] = {
  94.     { XAD_DATECURRENTTIME, 1 },
  95.     { XAD_GETDATEXADDATE,  0 },
  96.     { TAG_DONE, 0 }
  97.   };
  98.  
  99.   struct xadFileInfo *link, *fi;
  100.   struct SOSfile file;
  101.   struct SOSboot boot;
  102.   LONG err;
  103.   int n;
  104.  
  105.   /* check the image */
  106.   if (ai->xai_ImageInfo->xii_SectorSize != 512) return XADERR_FILESYSTEM;
  107.  
  108.  
  109.   /* check the bootblock */
  110.   if ((err = xadHookAccess(XADAC_READ, BOOTSIZE, &boot, ai))) return err;
  111.   if ((err = xadHookAccess(XADAC_INPUTSEEK, BOOTSEEK, 0, ai))) return err;
  112.   if (EndConvM32(boot.dostype) != 0x444f5300
  113.   ||  EndConvM32(boot.id)      != 0x534f5331) return XADERR_FILESYSTEM;
  114.  
  115.  
  116.   /* search blocks 2-29 for the first directory block */
  117.   for (n = 2; n < 30; n++) {
  118.     if ((err = xadHookAccess(XADAC_INPUTSEEK, FILESEEK, 0, ai))) return err;
  119.     if ((err = xadHookAccess(XADAC_READ, FILESIZE, &file, ai)))  return err;
  120.     if (strncmp("loader", file.name, 24) == 0) break;
  121.   }
  122.   if (n == 30) return XADERR_FILESYSTEM;
  123.  
  124.   /* main directory entry loop */
  125.   link = NULL; n = 1;
  126.  
  127.   /* loop ends on entry where offset = 0 */
  128.   while (!err && file.offset != 0) {
  129.     fi = (struct xadFileInfo *) xadAllocObjectA(XADOBJ_FILEINFO, tags);
  130.     if (fi) {
  131.       fi->xfi_EntryNumber = n++;
  132.       fi->xfi_Flags       = XADFIF_NODATE | XADFIF_SEEKDATAPOS;
  133.       fi->xfi_Size        = fi->xfi_CrunchSize = EndConvM32(file.size);
  134.       fi->xfi_DataPos     = EndConvM32(file.offset);
  135.       xadCopyMem(file.name, fi->xfi_FileName, 24);
  136.  
  137.       /* fill in today's date */
  138.       datetags[1].ti_Data = (ULONG) &fi->xfi_Date;
  139.       xadConvertDatesA(datetags);
  140.  
  141.       if (link) link->xfi_Next   = fi;    /* link into list */
  142.       else      ai->xai_FileInfo = fi;    /* write head of list */
  143.       link = fi;
  144.  
  145.       /* read next entry */
  146.       err = xadHookAccess(XADAC_READ, FILESIZE, &file, ai);
  147.     }
  148.     else {
  149.       err = XADERR_NOMEMORY;
  150.     }
  151.   }
  152.  
  153.   /* handle errors */
  154.   if (err) {
  155.     if (!ai->xai_FileInfo) return err;
  156.     ai->xai_Flags |= XADAIF_FILECORRUPT;
  157.     ai->xai_LastError = err;
  158.   }
  159.   return XADERR_OK;
  160. }
  161.  
  162.  
  163. ASM(LONG) SOS_UnArchive(REG(a0, struct xadArchiveInfo *ai),
  164. REG(a6, struct xadMasterBase *xadMasterBase)) {
  165.   return xadHookAccess(XADAC_COPY, ai->xai_CurFile->xfi_Size, NULL, ai);
  166. }
  167.  
  168.  
  169. const struct xadClient SOS_Client = {
  170.   NEXTCLIENT, XADCLIENT_VERSION, 5, SOS_VERSION, SOS_REVISION,
  171.  
  172.   0,                        /* minimum archive size     */
  173.   XADCF_FILESYSTEM | XADCF_FREEFILEINFO,    /* type of client and flags */
  174.   0,                        /* internal ID (not needed) */
  175.   "SanityOS FS",                /* name of client           */
  176.  
  177.   /* client functions */
  178.   (BOOL (*)()) NULL,
  179.   (LONG (*)()) SOS_GetInfo,
  180.   (LONG (*)()) SOS_UnArchive,
  181.   (void (*)()) NULL
  182. };
  183.